
//添加管理员
$(".btnadd").on('click',function (e) {
    e.stopPropagation();
    e.preventDefault();
    var url="http://localhost:8080/addAdmin1";
    var username=$(".username2").val().trim();
    var mobile=$(".mobile2").val().trim();
    var realname=$(".realname2").val().trim();
    var roleId=$(".roleId2").val().trim();
    console.log(roleId);
    $.ajax({
        type:"post",
        url:url,
        data:{"username":username,"mobile":mobile,"realname":realname,"roleId":roleId},
        success:function (data) {
            if(data.status==1){
                alert(data.msg);
            }else {
                alert(data.msg);
            }
        },
        fail:function () {
            alert("服务器繁忙");
        },
        complete:function () {
            $("body").load("http://localhost:8080/admin");
        }
    })
});

//修改方法,数据回填
$(".mod").on('click',function () {
    console.log("进入修改方法");
    var adminId = $(this).attr('data-id');
    console.log(adminId);
    var url="http://localhost:8080/putInform?adminId="+adminId;
    $.ajax({
        type:"get",
        url:url,
        success:function (data) {
            $(".managerList").css('display',"none");
            $(".modifyAdmin").css('display',"block");
        },
        fail:function () {
            alert("服务器繁忙")
        },
        complete:function (data) {
            $(".modifyAdmin").load(url);
        }
    })
});

//修改管理员保存
$(".btn2").on('click',function (e) {
    e.stopPropagation();
    e.preventDefault();
    console.log("进入修改方法aaaaa");
    var username=$(".username1").val().trim();
    var mobile=$(".mobile1").val().trim();
    var realname=$(".realname1").val().trim();
    var roleId=$(".roleId1").val().trim();
    var url="http://localhost:8080/modifyAdmin";
    $.ajax({
        type:"post",
        url:url,
        data:{"username":username,"mobile":mobile,"realname":realname,"roleId":roleId},
        timeout:2000,
        before:function (result) {
            console.log("进入成功方法");
            if (result.status==1){
                alert(result.msg);
            }else {
                alert(result.msg);
            }
        },complete:function () {
            $("body").load("http://localhost:8080/admin");
        },
        success:function(){

        },
        fail:function () {
            alert("服务器繁忙")
        },

    })
});
//删除管理员
$(".del").on('click',function () {
    var adminId = $(this).attr('data-id');
    console.log(adminId);
    var url = "http://localhost:8080/deleteAdmin?adminId=" + adminId;
    $.ajax({
        type: 'DELETE',
        url: url,
        success: function (data) {
            if (data.status == 1) {
                alert(data.msg);
            } else {
                alert(data.msg);
            }
        },
            fail:function () {
            alert("服务器繁忙");
            },
        complete:function () {
            console.log("执行了方法");
            $("body").load("http://localhost:8080/admin");
        }

    })
});

$("#addManagerBtn").on('click',function () {
    $(".managerList").css('display',"none");
    $(".addForm").css('display',"block");
});
$(".retbtn").on('click',function () {
    $(".addForm").css('display',"none");
    $(".managerList").css('display',"block");
});
$(".retbtn1").on('click',function () {
    $(".modifyAdmin").css('display',"none");
    $(".managerList").css('display',"block");
});